<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>力士h5</title>
<meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"/>
<script src="//g.alicdn.com/tmapp/tida2/2.2.15/tida.js?appkey=23164248"></script>
<script src="//res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script type="text/javascript" src="static/js/zepto.min.js"></script>
<script type="text/javascript" src="static/js/interface.js"></script>
</head>
<body>
<style type="text/css">
	html,body{
		margin: 0;
		padding: 0;
   		width:100%;
    	height:100%;
    	overflow: hidden;
	}
</style>
<script type="text/javascript">
  var ua = navigator.userAgent.toLowerCase();//获取判断用的对象
  window.dschannel = '';
  if (ua.match(/MicroMessenger/i) == "micromessenger") {
      //在微信中打开
      window.dschannel = "weixin";
  }

	if(Tida.isSupportedApp){//淘系
	  Tida.ready({
	    debug:0,
	    combo:0,
	    module:["device", "media", "server", "social", "widget", "sensor", "share","buy","draw","im","calendar","prize"]
	  }, function(){

	    var options = {
	      sellerNick: ""
	    };

	    Tida.mixNick(options, function (data) {
	    	gameStart();
	    });

	  });
	}else if(window.dschannel=='weixin'){//微信
	  	$.ajax({
			url:"/interface/wechat/signature/get",
			type:"POST",
			dataType:"json",
			data:{url:encodeURIComponent(location.href)},
			success:function(result){
				console.log(result);
				// alert(JSON.stringify(result.data));
				wxConfig(result.data);
			},
			error:function(){

			}
		});
		$(document).ready(function(){
			var openid = $('input[name=m0j1t2]').val()||'';
			if(openid==''){
				var url = 'https://vrbuy.ews.m.jaeapp.com/lux/index';
				var oauthurl = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx6d5c659db53fee95&redirect_uri='+url+'&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect';
				location.href = oauthurl;
			}
		});

		gameStart();
	}else{
		$(document).ready(function(){
          $('body').html('请用手淘或者微信打开');
        });
	}


	function gameStart(){
		window.interface.login(function(chance){
    		console.log(chance);
    		window.chance = chance;
    		alert('登录成功');
    	});

		$(document).ready(function(){
			$('#award').on('click',function(){
				if(window.chance<=0){
					alert('你抽过了');
					return;
				}
				alert('开始抽奖');
				window.interface.lottery(function(award){
					console.log(award);
					if(award==1){
						alert('中奖了');
					}else{
						alert('没中奖');
					}
				});
			});

			$('#submit').on('click',function(){
				var realname = 'aaa'+Math.floor(Math.random()*1000);
				var phone = 'bbb'+Math.floor(Math.random()*1000);
				var address = 'ccc'+Math.floor(Math.random()*1000);
				alert('realname:'+realname+',phone:'+phone+',address:'+address);
				window.interface.submitInfo({realname:realname,phone:phone,address:address},function(result){
					if(result){
						alert('提交成功');
					}else{
						alert('提交失败');
					}
				});
			});
		});		
	}

	function wxConfig(data){
	  wx.config({
	      //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
	      appId: 'wx6d5c659db53fee95', // 必填，公众号的唯一标识
	      timestamp: data.timestamp, // 必填，生成签名的时间戳
	      nonceStr: data.nonceStr, // 必填，生成签名的随机串
	      signature: data.signature,// 必填，签名，见附录1
	      jsApiList: ['onMenuShareTimeline',
	        'onMenuShareAppMessage',
	        'onMenuShareQQ',
	        'onMenuShareWeibo',
	        'onMenuShareQZone',
	        'hideMenuItems',
	        'showMenuItems'
	      ] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
	  });
	  wx.ready(function(){
	    // alert("wxReady");
	    console.log("wxReady");
	      // config信息验证后会执行ready方法，所有接口调用都必须在config接口获得结果之后，config是一个客户端的异步操作，所以如果需要在页面加载时就调用相关接口，则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口，则可以直接调用，不需要放在ready函数中。
	    // var iteamid = getQueryStringByName('id');
	    var url = location.href;
	    var shareData={
	        title: '力士标题', // 分享标题
	        desc: '力士描述', // 分享描述
	        link: url, // 分享链接
	        imgUrl: 'https://vrbuy.ews.m.jaeapp.com/lux/static/images/share2.jpg', // 分享图标
	        success: function () { 
	           // 用户确认分享后执行的回调函数
	           // alert("shareSuccess");
	        },
	        cancel: function () { 
	            // 用户取消分享后执行的回调函数
	        }
	    };
	    //朋友圈
	    wx.onMenuShareTimeline(shareData);
	    //朋友
	    wx.onMenuShareAppMessage(shareData);
	    //qq
	    wx.onMenuShareQQ(shareData);
	    //腾讯微博
	    wx.onMenuShareWeibo(shareData);
	    //qq空间
	    wx.onMenuShareQZone(shareData);
	  });
	}	
</script>
<img style="display: none;" src="https://vrbuy.ews.m.jaeapp.com/lux/static/images/share2.jpg"/>
<!-- <div id="loading"></div> -->
<div id="app" class="table" style="width:100%;height:100%;">
	<button id="award">抽奖</button>
	<button id="submit">提交</button>
</div>
</body>
</html>